<!--
 * @Author: 王明明834578987 10266004+wang-mingming-834578987@user.noreply.gitee.com
 * @Date: 2024-08-29 10:59:23
 * @LastEditors: 王明明834578987 10266004+wang-mingming-834578987@user.noreply.gitee.com
 * @LastEditTime: 2024-10-21 15:32:48
 * @FilePath: \ft-apply-admin\src\views\ApplicationList\components\yypxModal.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <BasicModal :show="show" title="预约培训" width="30%" :widthComfirm="true" @comfirm="comfirm" @closeModal="closeModal">
    <template #content>
      <CommonForm v-if="show" :formList="formList" ref="formRef"></CommonForm>
    </template>
  </BasicModal>
</template>

<script setup lang="ts">
import CommonForm from "@/views/applicationDetails/CommonForm.vue";
import BasicModal from "./BasicModal.vue";
import { comStores } from "../../../store/common/comStore";
const store = comStores()
const { userInFor } = store as any
import { ref, watch } from "vue"
import { IndexFormItem } from "../../applicationDetails/application-type";
import { selectTrainingNumberList, trainingSchedule } from "../../../api/application-details";
import { joinTrainingNumber } from '@/api/applay/applicationList/self'
import { message } from "ant-design-vue";
const show = ref<boolean>(false)
const paramsList = () => ([
  {
    label: "培训期数", name: "trainingId", value: "", component: 'cascader', options: [
    ]
  },
  {
    label: "口味选择", name: "taste", value: "", component: 'select', required: false, options: [
      {
        label: "清真",
        value: "清真"
      }
      , {
        label: "非清真",
        value: "非清真"
      }
    ]
  },
  { label: "忌口食物", name: "notEat", value: "", disabled: true, component: 'textarea', required: false },
  { label: "备注", name: "remark", value: "", disabled: true, component: 'textarea', required: false },
  { label: "发送邮件通知", name: "isSend", value: true, component: 'isSend', required: false },
])
const formList = ref<IndexFormItem[]>(paramsList())
const emits = defineEmits(['onSuccess'])
const formRef = ref<any>(null)
const comfirm = async () => {
  const res = await formRef.value.submitForm();
  const param: any = {
    resumeId: info.value.id,
    processId: info.value.processId,
    result: "通过",
    operator: userInFor.userName,
  }
  res.forEach(el => {
    param[el.name] = el.value
  })
  param.trainingId = res[0].value[2];
  console.log(param)
  const data: any = await trainingSchedule(param)
  if (data && data.code === '10000') {
    message.success("操作成功")
    emits('onSuccess')
    show.value = false
    formList.value = paramsList()
  } else {
    message.error(data.msg)
  }
}
watch(() => show.value, async (val) => {
  if (val) {
    const data: any = await selectTrainingNumberList();
    console.log(data, '===>daat')
    if (data && data.code === '10000') {
      data.data.forEach(l1 => {
        l1.label = l1.dateTime
        l1.value = l1.dateTime
        l1.children = l1.monthList
        l1.monthList.forEach(l2 => {
          l2.label = l2.dateTime
          l2.value = l2.dateTime
          l2.children = l2.numberList
          l2.numberList.forEach(l3 => {
            l3.label = l3.startTimeEndTime + (l3.isOnline == 0 ? ' (未上线)' : "")
            l3.value = l3.trainingNumberId
          })
        })
      })
      formList.value[0].options = data.data
    }
  }
})
const info = ref<any>({});
const open = (params: any) => {
  info.value = params.info
  console.log('打开弹框', params.info)
  show.value = true
}
const closeModal = () => {
  show.value = false
  formList.value = paramsList()
  formRef.value.clear()
}
defineExpose({ open })
</script>

<style lang="less" scoped></style>
